<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /*
            ①：确定终止条件
            ②：确定遍历集合范围

            */
            var combine = function (n, k) {
                let res = []
                let path = []
                function backTacking(path, startIndex) {
                    if (path.length == k) {
                        return res.push([...path])
                    }
                    for (let i = startIndex + 1; i <= n; i++) {
                        path.push(i)
                        backTacking(path, i)
                        path.pop()
                    }
                }
                backTacking(path, 0)
                return res
            }
            console.log(combine(4, 2))
        </script>
    </body>
</html>
